/**
 * 
 */


$(window.document).ready(function(){
	alert("jQuery binding OK");

	
	document.onkeydown = keyevent;

	
	
	//button binding
	buttonEventBinding();
});

function keyevent(){
	if(event.keyCode==37)	moveLeft();
	if(event.keyCode==38)	moveUp();
	if(event.keyCode==39)	moveRight();
	if(event.keyCode==40)	moveDown();
}

function moveLeft(){
	$("#monitor").html("Left");
	alert("sendMessageStart!!");
	sendMessage("L","10");
	alert("sendMessageEnd!!");
}

function sendMessage(direction,distance){
	alert("반영됨");
	var url = "remoconAjax.json?direction="+direction+"&distance="+distance;
	$.ajax({
		   type: "POST",
		   url: url,
		   dataType:"json",
		   data: "direction="+direction+"&distance="+distance,
		   async:false,
		   success: function(data){
			   alert("success!!");
			   alert(data);
		     if(data.avatarVO!=null){
		    	 alert(		" top : "+ data.avatarVO.rightPosition
		    			+	", left : "+ data.avatarVO.leftPosition		);
		     }
		   },
		   error: function(){
			   alert("error");
		   }
		 });
}

function moveUp(){
	$("#monitor").html("Up");
}
function moveRight(){
	$("#monitor").html("Right");
}
function moveDown(){
	$("#monitor").html("Down");
}

function buttonEventBinding(){
	$("#btnLeft").click(function(){
		moveLeft();
	});
	$("#btnUp").click(function(){
		moveUp();
	});
	$("#btnRight").click(function(){
		moveRight();
	});
	$("#btnDown").click(function(){
		moveDown();
	});
}